package com.iscas.tech.controller;

import com.iscas.tech.entity.AtStpic;
import com.iscas.tech.param.AtStpicPageParam;
import com.iscas.tech.service.AtStpicService;
import com.iscas.tech.vo.AtStpicQueryVo;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.pagination.Paging;
import io.geekidea.springbootplus.framework.shiro.util.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 科技成果图片信息表 控制器
 *
 * @author yangyi
 * @since 2020-10-26
 */
@Slf4j
@RestController
@RequestMapping("/techPic")
@Api(value = "科技成果图片信息表API", tags = {"科技成果图片信息表"})
public class AtStpicController extends BaseController {

    @Autowired
    private AtStpicService atStpicService;

    /**
     * 添加科技成果图片信息表
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加科技成果图片信息表", response = ApiResult.class)
    public ApiResult<Boolean> addAtStpic(AtStpic atStpic) throws Exception {
        if (LoginUtil.getUserId() == null) {
            return ApiResult.fail(ApiCode.UNAUTHORIZED);
        }
        atStpic.setCreatetitle(LoginUtil.getUserId().intValue());
        boolean flag = atStpicService.saveAtStpic(atStpic);
        return ApiResult.result(flag);
    }

    /**
     * 修改科技成果图片信息表
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改科技成果图片信息表", response = ApiResult.class)
    public ApiResult<Boolean> updateAtStpic(AtStpic atStpic) throws Exception {
        boolean flag = atStpicService.updateAtStpic(atStpic);
        return ApiResult.result(flag);
    }

    /**
     * 删除科技成果图片信息表
     */
    @RequestMapping(value = "delete", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "删除科技成果图片信息表", response = ApiResult.class)
    public ApiResult<Boolean> deleteTechPic(String ids) throws Exception {
        return ApiResult.result(atStpicService.deleteTechPic(ids));
    }

    /**
     * 获取科技成果图片信息表详情
     */
    @RequestMapping(value = "info", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "科技成果图片信息表详情", response = AtStpic.class)
    public ApiResult<AtStpic> getAtStpic(Long id) throws Exception {
        AtStpic atStpic = atStpicService.getById(id);
        return ApiResult.ok(atStpic);
    }

    /**
     * 科技成果图片信息表分页列表
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "科技成果图片信息表分页列表", response = AtStpic.class)
    public ApiResult<Paging<AtStpicQueryVo>> getAtStpicPageList(AtStpicPageParam atStpicPageParam) throws Exception {
        Paging<AtStpicQueryVo> paging = atStpicService.getAtStpicPageList(atStpicPageParam);
        return ApiResult.ok(paging);
    }

    /**
     * @param techGainId  科技成果ID
     * @param techPicType {@link com.iscas.tech.bo.TechPicType}科技成果图片分类
     * @return 获取科技成果下属所有图片
     */
    @GetMapping("/getByGainId")
    @ApiModelProperty(value = "获取科技成果下属所有图片")
    public ApiResult<List<AtStpicQueryVo>> getByGainId(Integer techGainId, Integer techPicType) throws Exception {
        return ApiResult.ok(atStpicService.getByGainId(techGainId, techPicType));
    }

}

